package io.ent.modules.mis.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.ent.common.utils.PageUtils;
import io.ent.common.utils.R;
import io.ent.common.validator.ValidatorUtils;
import io.ent.modules.mis.entity.MisCustomerEntity;
import io.ent.modules.mis.service.MisCustomerService;
import io.ent.modules.sys.controller.AbstractController;
import io.ent.modules.sys.shiro.ShiroUtils;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



/**
 * 
 *
 * 
 * 
 * 
 */
@RestController
@RequestMapping("mis/miscustomer")
public class MisCustomerController extends AbstractController{
    @Autowired
    private MisCustomerService misCustomerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:miscustomer:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = misCustomerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:miscustomer:info")
    public R info(@PathVariable("id") Integer id){
        MisCustomerEntity misCustomer = misCustomerService.getById(id);

        return R.ok().put("misCustomer", misCustomer);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:miscustomer:save")
    public R save(@RequestBody MisCustomerEntity misCustomer){
    	String username = ShiroUtils.getUserEntity().getUsername();
    	misCustomer.setCreater(username);
    	misCustomer.setCreateDay(new Date());
    	misCustomer.setUpdateDay(new Date());
        misCustomerService.save(misCustomer);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:miscustomer:update")
    public R update(@RequestBody MisCustomerEntity misCustomer){
        ValidatorUtils.validateEntity(misCustomer);
        misCustomer.setUpdateDay(new Date());
        misCustomerService.updateById(misCustomer);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:miscustomer:delete")
    public R delete(@RequestBody Integer[] ids){
        misCustomerService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
